// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import 'font-awesome/css/font-awesome.min.css'
import ElementUI from 'element-ui'
import './assets/theme/element-#4089FF/index.css'
import Vuex from 'vuex'
import store from './store/store.js'
import axios from 'axios'


import VueI18n from 'vue-i18n';
import { messages } from './components/base/i18n';
import './assets/css/icon.css';
import './components/base/directives';
import "babel-polyfill";

Vue.config.productionTip = false


Vue.use(VueI18n);
Vue.use(ElementUI, {
    size: 'small'
});
const i18n = new VueI18n({
    locale: 'zh',
    messages
})

Vue.use(Vuex)
Vue.prototype.$axios = axios
Vue.prototype.$store = store
axios.defaults.headers.common['Authentication'] = store.state.token;
/* eslint-disable no-new */
new Vue({
  el: '#app',
  store,
  router,
  i18n,
  components: {
    App
  },
  template: '<App/>'
})

// 添加请求拦截器
axios.interceptors.request.use(config => {
  // 在发送请求之前做些什么
  //判断是否存在token，如果存在将每个页面header都添加token
  if (store.state.token) {
    config.headers.common['Authentication-Token'] = store.state.token
  }

  return config;
}, error => {
  // 对请求错误做些什么
  return Promise.reject(error);
});

// http response 拦截器
/*axios.interceptors.response.use(
  response => {

    return response;
  },
  error => {

    if (error.response) {
      switch (error.response.status) {
        case 401:
          this.$store.commit('del_token');
          router.replace({
            path: '/login',
            query: {
              redirect: router.currentRoute.fullPath
            } //登录成功后跳入浏览的当前页面
          })
      }
    }
    return Promise.reject("error.response.msg")
  });
*/